﻿using System;
using System.Windows.Forms;
using EasyTagWinForm.Model;
using System.Collections.Generic;

namespace EasyTagWinForm
{
  public partial class Form1 : Form
  {
    public string[] args { get; set; } = null;
    public string dir { get; set; } = null;

    public Form1()
    {
      InitializeComponent();
    }

    public Form1(string[] args)
    {
      InitializeComponent();
      this.args = args;
      FileHandler fileHandler = new FileHandler(args[0]);
      this.dir = fileHandler.FileDir;
      MessageBox.Show(args.Length.ToString());
      if (args.Length == 2)
      {
        FileName.Visible = true;
        FileNameHeader.Visible = true;
        FileName.Text = fileHandler.FileName;
      }
      else if (args.Length < 2)
      {
        MessageBox.Show("Error");
      }
      else
      {
        FileName.Visible = false;
        FileNameHeader.Visible = false;
      }
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    }

    private void groupBox1_Enter(object sender, EventArgs e)
    {
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    }

    private void Btn_tagSubmit_Click(object sender, EventArgs e)
    {
      string tagText = textBox1.Text;
      TagCacheHandler cacheHandler = new TagCacheHandler(dir,GetTagInfos(args, tagText));
      if (cacheHandler.HasCache)
      {
        MessageBox.Show("has created cacheFile");
      }
    }

    private List<TagInfo> GetTagInfos(string[] args,string tagText)
    {
      List<TagInfo> tagInfos = new List<TagInfo>();
      for (int i = 0; i < args.Length-1; i++)
      {
        tagInfos.Add(new TagInfo { TagPath = args[i], TagName = tagText });
      }
      return tagInfos;
    }
  }
}